package com.stu.mapper;

import com.stu.annotation.AutoFill;
import com.stu.enumeration.OperationType;
import com.stu.pojo.StuBasicInformation;
import com.stu.pojo.StuFamilyInformation;
import com.stu.pojo.StuOtherInformation;
import com.stu.vo.StuInformationVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StuInformationMapper {
    /**
     * 插入学生基本信息
     * @param stuBasicInformation
     */
    @AutoFill(value = OperationType.INSERT)
    void insert_basic(StuBasicInformation stuBasicInformation);

    /**
     * 插入学生家庭信息
     * @param stuFamilyInformations
     */
    void insert_family(List<StuFamilyInformation> stuFamilyInformations);

    /**
     * 插入学生其他信息
     * @param stuOtherInformation
     */
    void insert_other(StuOtherInformation stuOtherInformation);

    /**
     * 更新学生基础信息
     * @param stuBasicInformation
     */
    @AutoFill(value = OperationType.UPDATE)
    void update_basic(StuBasicInformation stuBasicInformation);

    /**
     * 更新学生其他信息
     * @param stuOtherInformation
     */
    void update_other(StuOtherInformation stuOtherInformation);

    /**
     * 根据stuId删除对应的学生家庭信息
     * @param stuId
     */
    @Delete("delete from stu_message.stu_family_information where stu_basic_id = #{stuId}")
    void deleteFamilyByBasicId(Integer stuId);

    /**
     * 根据id删除学生的basic、family、other数据
     * @param ids
     */
    void deleteBasicByIds(List<Long> ids);
    void deleteFamilyByBasicIds(List<Long> ids);
    void deleteOtherByBasicIds(List<Long> ids);


    /**
     * 根据id查询学生个人信息
     * @param id
     * @return
     */
    @Select("select * from stu_basic_information where id = #{id}")
    StuBasicInformation selectBasicById(Long id);

    /**
     * 根据外键stu_id查询学生基础表的信息
     * @param currentId
     * @return
     */
    @Select("select * from stu_basic_information where id = #{currentId}")
    StuBasicInformation selectBassicByStuId(Long currentId);

    /**
     * 根据id查询学生家庭信息
     * @param id
     * @return
     */
    @Select("select * from stu_family_information where stu_basic_id = #{id}")
    List<StuFamilyInformation> selectFamilyById(Long id);

    /**
     * 根据id查询学生其他信息
     * @param id
     * @return
     */
    @Select("select * from stu_other_information where stu_basic_id = #{id}")
    StuOtherInformation selectOtherById(Long id);

    @Select("select id from stu_family_information where stu_basic_id = #{stu_id}")
    Integer selectFamilyIdByStuId(String stuId);

    @Select("select id from stu_other_information where stu_basic_id = #{stu_id}")
    Integer selectOtherIdByStuId(String stuId);

    /**
     * 分页查询全部学生信息
     */
    List<StuInformationVo> selectAllStuINF(String classInfo, String name, Integer gender, String college, Integer age,
                                           String politicalOutlook, String major);

    /**
     * 修改或添加学生照片
     *
     * @param image
     * @param currentId
     */
    @Update("update stu_basic_information set image = #{image} where id = #{currentId}")
    void InsertStuImage(String image, Long currentId);

    @Select("select id from stu_basic_information where stu_id = #{stuId}")
    Integer selectIdByStuId(String stuId);
}
